var t = getApp(), a = require("../../wxParse/wxParse.js");

Page({
    data: {
        language: "",
        store_id: "",
        lingquBox: !0,
        newGmBox: !0,
        boxShow: !0,
        bosPto: !0,
        audio_link: "",
        songStop: !0,
        infoList: {},
        poster_open: 0,
        poster_show: !1,
        poster_url: "",
        show: !1
    },
    onLoad: function(a) {
        if (console.log(a), this.setData({
            kind: a.id,
            store_id: a.store_id
        }), a.share_tag && (this.data.share_uid = a.mid), a.scene) {
            var e = decodeURIComponent(a.scene);
            if (e) {
                var i = [];
                i = e.split("&");
                for (var s = 0; s < i.length; s++) {
                    var o;
                    o = i[s].split("="), console.log("59", o), "id" == o[0] ? this.setData({
                        kind: o[1]
                    }) : "mid" == o[0] && (t._setMid(o[1]), this.data.share_uid = o[1]);
                }
            }
        }
    },
    tapLoadWatch: function(t) {
        var a = t.currentTarget.dataset.img;
        wx.previewImage({
            current: a,
            urls: [ a ]
        });
    },
    setPosterShow: function() {
        this.setData({
            poster_show: !this.data.poster_show
        });
    },
    getPosterImage: function() {
        var a = this;
        if ("" == this.data.poster_url) {
            var e = t.getNetAddresss("plugin.share-activity.frontend.activity.get-poster");
            t._getNetWork({
                data: {
                    activity_id: this.data.kind
                },
                url: e,
                success: function(t) {
                    var e = t.data;
                    1 == e.result && a.setData({
                        poster_show: !0,
                        poster_url: e.data.poster
                    });
                }
            });
        } else this.setData({
            poster_show: !0
        });
    },
    toGoods: function() {
        if (Date.parse(new Date()) / 1e3 < this.data.infoList.star_time) wx.showToast({
            title: "还没到开始时间",
            icon: "none",
            duration: 1500
        }); else if (Date.parse(new Date()) / 1e3 > this.data.infoList.end_time) wx.showToast({
            title: "活动已结束",
            icon: "none",
            duration: 1500
        }); else {
            var t = this.data.infoList.diyform_id;
            console.log(t);
            var a = "";
            a = (a = t ? "/packageC/diyform/diyform?scene=" + t : "/packageD/buy/myOrder_v2/myOrder_v2?tag=-2") + "&goodsId=" + this.data.infoList.goods_id + "&optionsId=" + this.data.infoList.option_id + "&total=" + this.data.infoList.total, 
            this.data.store_id && (a = a + "&store_id=" + this.data.store_id), a = a + "&activity_id=" + this.data.kind, 
            this.data.share_uid && (a = a + "&share_uid=" + this.data.share_uid), wx.navigateTo({
                url: a
            });
        }
    },
    countdown: function() {
        var t = this, a = new Date(), e = String(Date.parse(a)).substr(0, 10), i = this.data.infoList.end_time;
        if (i - e <= 0) return console.log(i, e), void this.setData({
            stop: !1
        });
        var s = i - e, o = parseInt(s / 60 / 60 / 24), n = parseInt(s / 60 / 60 % 24), r = parseInt(s / 60 % 60), d = parseInt(s % 60);
        n = n > 9 ? n : "0" + n, r = r > 9 ? r : "0" + r, d = d > 9 ? d : "0" + d, this.setData({
            Day: o,
            Hour: n,
            Min: r,
            Sec: d
        }), setTimeout(function() {
            t.countdown();
        }, 1e3);
    },
    handleContact: function(t) {
        console.log(t.detail.path), console.log(t.detail.query);
    },
    linkTomember: function() {
        wx.reLaunch({
            url: "/packageG/member_v2/member_v2"
        });
    },
    linkToorder: function() {
        wx.navigateTo({
            url: "/packageA/member/myOrder_v2/myOrder_v2?status=0"
        });
    },
    setDataByTabIndex: function() {
        this.setData({
            first_content: this.data.infoList.agreement
        });
        var t = this.data.first_content;
        t.indexOf("&#") <= -1 && a.wxParse("article", "html", t, this), console.log("1111111111111111");
    },
    replaceDetail: function(t) {
        for (var a = ""; -1 != t.indexOf("<img"); ) a += t.substring("0", t.indexOf("<img") + 4), 
        -1 != (t = t.substring(t.indexOf("<img") + 4)).indexOf("style=") && t.indexOf("style=") < t.indexOf(">") ? (a += t.substring(0, t.indexOf('style="') + 7) + "max-width:100%;height:auto;margin:0 auto;", 
        t = t.substring(t.indexOf('style="') + 7)) : a += ' style="max-width:100%;height:auto;margin:0 auto;" ';
        return a += t;
    },
    tapOn: function() {
        this.setData({
            boxShow: !this.data.boxShow
        });
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    onShow: function() {
        this.getData();
    },
    onHide: function() {
        this.audioCtx.pause();
    },
    onUnload: function() {
        this.audioCtx.destroy();
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareTimeline: function() {
        var t = wx.getStorageSync("yz_uid"), a = "";
        return t && (a = t), {
            title: this.data.share_title,
            query: "id=" + this.data.kind + "&mid=" + a + "&share_tag=2"
        };
    },
    onShareAppMessage: function() {
        var t = wx.getStorageSync("yz_uid"), a = 0;
        return t && (a = t), {
            title: this.data.share_title,
            path: "/packageD/ActivityDetail/ActivityDetail?id=" + this.data.kind + "&share_tag=2&mid=" + a
        };
    },
    makePhoneCall: function(t) {
        var a = t.currentTarget.dataset.iphone;
        wx.makePhoneCall({
            phoneNumber: a
        });
    },
    setShow: function() {
        this.setData({
            show: !this.data.show
        });
    },
    getData: function() {
        var a = t.getNetAddresss("plugin.share-activity.frontend.activity.index"), e = this;
        t._getNetWork({
            data: {
                activity_id: e.data.kind
            },
            url: a,
            success: function(a) {
                var i = a.data;
                1 == i.result && (t._isTextEmpty(i.data.background_thumb) && e.setData({
                    bosPto: !1
                }), i.data.agreement && (i.data.agreement = e.replaceDetail(i.data.agreement)), 
                e.setData({
                    infoList: i.data,
                    audio_link: i.data.audio_link,
                    browse_count: i.data.browse_count,
                    browse_member: i.data.browse_member,
                    share_content: i.data.share_content,
                    share_thumb: i.data.share_thumb,
                    share_title: i.data.share_title,
                    store_id: i.data.store_id,
                    poster_open: i.data.poster_open
                }), e.setDataByTabIndex(), e.countdown(), e.data.audio_link && (e.audioCtx = wx.createInnerAudioContext("myAudio"), 
                e.audioCtx.src = e.data.audio_link, e.audioCtx.autoplay = !0, e.audioPlay()), 1 == i.data.order_list && e.getOrderData(), 
                1 == i.data.award_list && e.getAwardData(), wx.setNavigationBarTitle({
                    title: i.data.name
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    audioPlay: function() {
        this.audioCtx.play(), this.setData({
            songStop: !1
        });
    },
    audioPause: function() {
        this.audioCtx.pause(), this.setData({
            songStop: !0
        });
    },
    getOrderData: function() {
        var a = this, e = {
            activity_id: a.data.kind
        }, i = t.getNetAddresss("plugin.share-activity.frontend.activity.getOrders");
        t._getNetWork({
            data: e,
            url: i,
            success: function(t) {
                var e = t.data;
                1 == e.result && (a.setData({
                    buy_count: e.data.buy_count,
                    orders: e.data.orders
                }), e.data.orders.length <= 4 && a.setData({
                    newGmBox: !1
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getAwardData: function() {
        var a = this, e = {
            activity_id: a.data.kind
        }, i = t.getNetAddresss("plugin.share-activity.frontend.activity.getAwards");
        t._getNetWork({
            data: e,
            url: i,
            success: function(t) {
                var e = t.data;
                1 == e.result && (a.setData({
                    award_count: e.data.award_count,
                    awards: e.data.awards
                }), e.data.awards.length <= 4 && a.setData({
                    lingquBox: !1
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    }
});